<template>
  <!-- 新增课程-编辑课程 -->
  <div class="content">
    <h2 class="u-title-h2">{{ $route.query.id ? '编辑' : '新增' }}商品</h2>
    <div class="u-form-box">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="150px"
        class="demo-ruleForm"
      >
        <el-form-item label="商品名称" prop="goods_name">
          <el-input
            v-model="ruleForm.goods_name"
            placeholder="请输入商品名称"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品类型" prop="goods_type">
          <el-select
            v-model="ruleForm.goods_type"
            placeholder="请选择商品类型"
            clearable
          >
            <el-option
              v-for="(item, index) in selectArr.goods_type"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="课程类型" prop="course_type">
          <el-select
            v-model="ruleForm.course_type"
            @change="getCourseByType"
            placeholder="请选择课程类型"
          >
            <el-option
              v-for="(item, index) in selectArr.course_type"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- prop="course_id" -->
        <div
          class="m-course-box"
          v-for="(itemA, indexA) in ruleForm.course_id"
          :key="indexA"
        >
          <!-- :rules="[{ required: true, message: '请选择关联课程', trigger: 'change' }]" -->

          <el-form-item
            label="关联课程"
            show-message
            :rules="[
              { required: true, message: '请选择关联课程', trigger: 'change' }
            ]"
            label-width="150px"
          >
            <el-select
              :disabled="!ruleForm.course_type"
              v-model="ruleForm.course_id[indexA]"
              filterable
              @change="courseChange($event, indexA, 'change')"
              :placeholder="
                ruleForm.course_type ? '请选择关联课程' : '请预先设置课程类型'
              "
            >
              <el-option
                v-for="(item, index) in courseArr"
                :key="index"
                :label="item.name"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>
          <!-- :rules="[{ required: true, message: '请选择对应课时', trigger: 'change' }]" -->
          <el-form-item label="对应课时" label-width="150px">
            <!--  -->
            <el-select
              :disabled="!ruleForm.course_type"
              v-model="ruleForm.course_time_id[indexA]"
              @change="courseTimeIdChange($event, indexA, 'change')"
              multiple
              filterable
              clearable
              :placeholder="
                ruleForm.course_type ? '请选择对应课时' : '请预先设置课程类型'
              "
            >
              <el-option
                v-for="(item, index) in courseTimeArr[indexA]"
                :key="index"
                :label="item.name"
                :value="item.id"
                >{{ '第' + item.sort + '课时：' + item.name }}</el-option
              >
            </el-select>
          </el-form-item>
        </div>
        <el-form-item label>
          <el-button
            type="primary"
            @click="addCourse"
            icon="el-icon-plus"
            circle
          ></el-button>
          <el-button
            type="danger"
            @click="deleteCourse"
            icon="el-icon-minus"
            circle
          ></el-button>
        </el-form-item>

        <el-form-item label="封面图片">
          <el-upload
            :http-request="uploadImg"
            class="avatar-uploader"
            :show-file-list="false"
            :before-upload="beforeUploadImg"
            action
          >
            <img
              v-if="ruleForm.main_pic"
              :src="ruleForm.main_pic"
              class="avatar"
            />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <p class="u-info-text">
            上传封面为.jpg.png格式，建议图片尺寸为800(宽)*378(高)，图片大小不超过2MB
          </p>
        </el-form-item>
        <!-- :show-message="originalPrice!=0" -->
        <!-- <el-form-item label="原价" prop="original_price" >
          <el-input
            v-model="ruleForm.original_price"
            min="0"
            oninput="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
            type="number"
            :placeholder="'请输入原价（保留两位）'"
          ></el-input> -->
        <!-- </el-form-item> -->
        <el-form-item label="价格(售价)" prop="retail_price">
          <el-input
            ref="retailPrice"
            :disabled="originalPrice == 0"
            v-model="ruleForm.retail_price"
            oninput="this.value=this.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3')"
            type="number"
            min="0"
            :placeholder="
              '请输入价格（原价：' + originalPrice + '元，保留两位）'
            "
          ></el-input>
          <!-- :disabled="originalPrice==0" -->

          <!-- 原价：'+originalPrice+'元  -->
        </el-form-item>
        <el-form-item label="上架时间" prop="list_time">
          <el-date-picker
            class="u-time-box"
            v-model="ruleForm.list_time"
            :editable="false"
            :placeholder="
              earliestTime
                ? '选择日期时间(不晚于' + earliestTime + ')'
                : '选择日期时间'
            "
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            @change="changeListTime"
            :picker-options="pickerOptions"
          ></el-date-picker>
        </el-form-item>
        <!-- format="yyyy 年 MM 月 dd 日 HH:mm:ss" -->
        <el-form-item label="下架时间">
          <el-date-picker
            class="u-time-box"
            :editable="false"
            v-model="ruleForm.delist_time"
            :placeholder="
              ruleForm.list_time
                ? '选择日期时间(不早于' + latestTime + ')'
                : '请先设置上架时间'
            "
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            :disabled="!ruleForm.list_time"
            :picker-options="pickerOptions"
            @change="setEndTime"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="商品标签：" prop="goods_tag">
          <el-select
            v-model="ruleForm.goods_tag"
            multiple
            filterable
            allow-create
            default-first-option
            placeholder="请选择商品标签"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="报名标签" prop="is_cardinal">
          <div class="margin-bottom10">
            <el-radio v-model="ruleForm.is_cardinal" label="0">
              购买基数
              <el-input
                v-model="ruleForm.apply_cardinal"
                placeholder="请输入购买基数"
                :disabled="ruleForm.is_cardinal == '1'"
                type="number"
              ></el-input>
            </el-radio>
          </div>
          <el-radio v-model="ruleForm.is_cardinal" label="1">
            展示标签
            <el-input
              v-model="ruleForm.cardinal_tag"
              placeholder="请输入标签名"
              :disabled="ruleForm.is_cardinal == '0'"
            ></el-input>
          </el-radio>
        </el-form-item>
        <el-form-item label="自定义商品日期" prop="custom_date">
          <el-input
            v-model="ruleForm.custom_date"
            placeholder="请输入自定义商品日期"
          ></el-input>
        </el-form-item>
        <el-form-item label="促销标签：" prop="activity_tag">
          <el-select
            v-model="ruleForm.activity_tag"
            multiple
            filterable
            allow-create
            default-first-option
            placeholder="请选择促销标签"
          >
            <el-option
              v-for="item in options1"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签样式" prop="activity_tag_style">
          <el-select
            v-model="ruleForm.activity_tag_style"
            placeholder="请选择标签样式"
          >
            <el-option
              v-for="(item, index) in tagOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="优先级" prop="priority">
          <el-input
            v-model="ruleForm.priority"
            placeholder="请输入优先级"
          ></el-input>
        </el-form-item>
        <el-form-item label="是否设置为推荐课程" prop="is_recommend">
          <el-radio v-model="ruleForm.is_recommend" :label="1">是</el-radio>
          <el-radio v-model="ruleForm.is_recommend" :label="0">否</el-radio>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >保存</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import {
  queyEnumByTableName,
  ossUpload,
  tableInsert,
  cascadeQuery
  // tableUpdate
} from '@/api/api.js'
import { courseListEunm } from '@/api/course.js'
import {
  queryGoodsById,
  getGoodsPrice,
  goodsUpdate,
  courseLatest,
  courseEarliest
} from '@/api/goods.js'

export default {
  data () {
    return {
      earliestTime: '',
      latestTime: '',
      originalPrice: 0,
      options: [],
      options1: [],
      tagOptions: [
        // {label:'绿色样式',value:'green'},
        { label: '橙色样式', value: '#FFA825' }
      ],
      pickerOptions: {
        disabledDate (date) {
          return date.getTime() < Date.now() - 8.64e7
        }
      },
      // pickerOptions2: {
      //   disabledDate: this.endDate
      // },
      courseArr: [],
      courseTimeArr: [],
      imageUrl: '',
      value2: null,
      selectArr: {
        status: [],
        course_type: [],
        course_id: [],
        goods_type: []
      },
      ruleForm: {
        goods_name: '',
        course_type: '',
        course_id: [''],
        course_time_id: [[]],
        main_pic: '',
        retail_price: '',
        list_time: '',
        delist_time: '',
        original_price: '',
        goods_tag: [],
        activity_tag: [],
        activity_tag_style: '',
        is_cardinal: '',
        apply_cardinal: '',
        cardinal_tag: '',
        custom_date: '',
        is_recommend: 0,
        priority: '',
        goods_type: ''
      },
      rules: {
        is_recommend: [
          { required: true, message: '是否设置为推荐课程', trigger: 'change' }
        ],
        is_cardinal: [
          { required: true, message: '请选择报名标签', trigger: 'change' }
        ],
        goods_name: [
          { required: true, message: '请输入商品名称', trigger: 'blur' },
          { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' }
        ],
        course_type: [
          { required: true, message: '请选择课程类型', trigger: 'change' }
        ],
        goods_type: [
          { required: true, message: '请选择商品类型', trigger: 'change' }
        ],
        goods_tag: [
          { required: true, message: '请选择商品标签', trigger: 'change' }
        ],
        apply_cardinal: [
          { required: true, message: '请输入购买基数', trigger: 'blur' }
        ],
        course_id: [
          {
            type: 'array',
            required: true,
            message: '请选择关联课程',
            trigger: 'change'
          }
        ],
        course_time_id: [
          { required: true, message: '请选择对应课时', trigger: 'change' }
        ],
        main_pic: [{ required: true, message: '请上传封面', trigger: 'blur' }],
        retail_price: [
          {
            required: true,
            message: '请输入价格（设置/关联课程/对应课时后生成原价）',
            trigger: 'blur'
          }
        ],
        original_price: [
          {
            required: true,
            message: '请输入原价（设置/关联课程/对应课时后生成）',
            trigger: 'blur'
          }
        ],
        list_time: [
          { required: true, message: '请选择上架时间', trigger: 'blur' }
        ],
        delist_time: [
          { required: true, message: '请选择下架时间', trigger: 'blur' }
        ]
      }
    }
  },
  watch: {
    'ruleForm.retail_price' (val, oldVal) {
      if (val > this.originalPrice) {
        this.ruleForm.retail_price = oldVal
      }
    }
  },
  created () {
    // if (!this.$route.query.id) {
    // this.getSelectData()
    // }
  },

  activated () {
    // if (this.$route.query.id) {
    this.getSelectData()
    // }
  },
  methods: {
    // endDate () {
    //   return this.ruleForm.list_time.getTime() < this.ruleForm.delist_time.getTime() - 8.64e7
    // },
    changeListTime () {
      this.ruleForm.delist_time = ''
    },
    addCourse () {
      this.ruleForm.course_id.push('')
      this.ruleForm.course_time_id.push([])
    },
    deleteCourse () {
      if (this.ruleForm.course_id.length > 1) {
        this.ruleForm.course_id.pop()
        this.ruleForm.course_time_id.pop()
      }
    },
    async courseTimeIdChange (e, indexA, type) {
      let num = 0
      this.ruleForm.course_time_id.map(item => {
        item.map(_item => {
          num += 1
        })
      })
      // 计算原价
      let res2 = await getGoodsPrice({
        'type_price.course_type': this.ruleForm.course_type,
        'stage_price.course_id': this.ruleForm.course_id,
        'level_price.course_id': this.ruleForm.course_id,
        'sum_price.num': num || 0
      })
      if (res2[0]) {
        return
      }
      // type==='all'?ruleForm.course_time_id[index]
      this.originalPrice = res2[1].data.sum_price
      if (this.ruleForm.retail_price) {
        this.ruleForm.retail_price = null
        this.$refs.retailPrice.focus()
      }
    },
    async courseChange (e, indexA, type) {
      let res = await cascadeQuery({
        table_name: 'nice_course_lesson',
        condition: [{ course_id: [{ in: this.ruleForm.course_id.join(',') }] }],
        by_order: 'course_id,sort'
      })
      if (res[0]) {
        return
      }
      this.courseTimeArr = []
      this.ruleForm.course_id.map(item => {
        this.courseTimeArr.push([])
      })
      res[1].data.map(item => {
        let index = this.ruleForm.course_id.indexOf(item.course_id.toString())
        let index_ = this.ruleForm.course_id.indexOf(item.course_id)
        let pushIndex
        if (index !== -1) {
          pushIndex = index
        } else if (index_ !== -1) {
          pushIndex = index_
        }
        if (pushIndex !== -1) {
          this.courseTimeArr[pushIndex].push(item)
        }
      })
      if (type === 'change') {
        this.ruleForm.course_time_id[indexA] = []
        this.courseTimeArr[indexA].map(item => {
          this.ruleForm.course_time_id[indexA].push(item.id)
        })
      }
      // // 计算原价
      let num = 0
      this.ruleForm.course_time_id.map(item => {
        item.map(_item => {
          num += 1
        })
      })
      console.log(this.ruleForm, indexA, 'this.ruleForm.this.ruleForm.')
      let res2 = await getGoodsPrice({
        'type_price.course_type': this.ruleForm.course_type,
        'stage_price.course_id': this.ruleForm.course_id,
        'level_price.course_id': this.ruleForm.course_id,
        'sum_price.num': num || 0
      })
      if (res2[0]) {
        return
      }
      // type==='all'?ruleForm.course_time_id[index]
      this.originalPrice = res2[1].data.sum_price
      if (this.ruleForm.retail_price) {
        this.ruleForm.retail_price = null
        this.$refs.retailPrice.focus()
      }
      this.getMaxMinTIme()
    },
    setEndTime (e) {
      if (this.ruleForm.list_time > this.ruleForm.delist_time) {
        this.ruleForm.delist_time = ''
        this.$message({
          message: '下架时间不得早于上架时间',
          type: 'warning'
        })
      }
    },
    // 上传封面至oss请求
    async uploadImg (e) {
      let formData = new FormData()
      formData.append('file', e.file)
      // 换商品封面
      let res = await ossUpload(formData, 'COURSE_COVER')
      if (res[0]) {
        return
      }
      this.ruleForm.main_pic = res[1].data.url
    },
    // 上传封面前验证
    beforeUploadImg (file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 或 PNG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    // 重新根据课程类型获取关联课程
    async getCourseByType () {
      this.originalPrice = 0
      if (this.ruleForm.retail_price) {
        this.ruleForm.retail_price = null
        this.$refs.retailPrice.focus()
      }
      this.ruleForm.course_id = [null]
      this.ruleForm.course_time_id = [[]]

      let res = await courseListEunm({
        'nice_course.type': this.ruleForm.course_type
      })
      if (res[0]) {
        return
      }
      this.courseArr = res[1].data.list
    },
    // 获取下拉菜单数据
    async getSelectData () {
      this.originalPrice = 0
      this.ruleForm = {
        goods_name: '',
        course_type: '',
        course_id: [''],
        course_time_id: [[]],
        main_pic: '',
        retail_price: '',
        original_price: '',
        list_time: '',
        delist_time: '',
        is_recommend: 0,
        goods_tag: [],
        activity_tag: [],
        activity_tag_style: '',
        is_cardinal: '0',
        apply_cardinal: '',
        cardinal_tag: '',
        custom_date: '',
        priority: '',
        goods_type: ''
      }
      this.$refs.ruleForm.resetFields()
      let res = await queyEnumByTableName({ tableName: 'nice_goods_virtual' })
      if (res[0]) {
        return
      }
      let arr = res[1].data
      Object.keys(this.selectArr).forEach(item => {
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].fieldName === item) {
            this.selectArr[item] = arr[i].child
          }
        }
      })
      let res2 = await courseListEunm({})
      if (res[0]) {
        return
      }
      this.courseArr = res2[1].data.list
      this.selectArr = JSON.parse(
        JSON.stringify(this.selectArr)
          .split('display_value')
          .join('label')
          .split('child')
          .join('children')
          .split('t_id')
          .join('value')
      )
      if (this.$route.query.id) {
        let res = await queryGoodsById({
          // table_name: 'nice_goods_virtual',
          id: this.$route.query.id
        })
        if (res[0]) {
          return
        }
        for (let i in this.ruleForm) {
          this.ruleForm[i] = res[1].data[0][i]
        }
        this.ruleForm.goods_tag = this.ruleForm.goods_tag
          ? this.ruleForm.goods_tag.split(',')
          : []
        this.ruleForm.activity_tag = this.ruleForm.activity_tag
          ? this.ruleForm.activity_tag.split(',')
          : []
        let res2 = await cascadeQuery({
          table_name: 'nice_goods_course',
          condition: [{ goods_id: [{ '=': this.$route.query.id }] }],
          member: 'course_name,course_lesson_ids'
        })
        if (res[0]) {
          return
        }
        this.ruleForm.course_id = []
        this.ruleForm.course_time_id = []
        // this.originalPrice = res[1].data[0].retail_price
        // this.ruleForm.retail_price = res[1].data[0].retail_price
        console.log(this.ruleForm, 'ruleFormruleForm')
        res2[1].data.map(item => {
          this.ruleForm.course_id.push(item.course_id.toString())
          let arr = item.course_lesson_ids.split(',')
          arr.map((item, index) => {
            arr[index] = item.toString()
          })
          this.ruleForm.course_time_id.push(arr)
        })
        this.courseChange(this.ruleForm.course_id)
        if (this.ruleForm.course_id && this.ruleForm.course_id.length > 1) {
          this.getMaxMinTIme()
        }
      }
      // this.selectArr.grade.unshift({ label: '全部', value: '', children: [] })
    },
    async getMaxMinTIme () {
      let res = await courseLatest({
        'vo.course_list': this.ruleForm.course_id.join(',')
      })
      if (!res) {
        return
      }
      this.latestTime = res[1].data.max_time
      let res2 = await courseEarliest({
        'vo.course_list': this.ruleForm.course_id.join(',')
      })
      if (!res2) {
        return
      }
      this.earliestTime = res2[1].data.min_time
    },
    handleAvatarSuccess (res, file) {
      this.imageUrl = URL.createObjectURL(file.raw)
    },
    beforeAvatarUpload (file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!')
      }
      return isJPG && isLt2M
    },
    submitForm (formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          if (parseFloat(this.ruleForm.retail_price) < 0) {
            this.$message({
              message: '检测价格小于0',
              type: 'warning'
            })
            return
          }
          if (
            this.ruleForm.is_cardinal == '0' &&
            !this.ruleForm.apply_cardinal
          ) {
            this.$message({
              message: '请输入购买基数！',
              type: 'warning'
            })
            return
          }
          if (this.ruleForm.is_cardinal == '1' && !this.ruleForm.cardinal_tag) {
            this.$message({
              message: '请输入展示标签！',
              type: 'warning'
            })
            return
          }
          let isFinash = true
          this.ruleForm.course_id.map(item => {
            if (!item || item === '') {
              isFinash = false
            }
          })
          if (!isFinash) {
            this.$message({
              message: '请选择至少一节关联课程',
              type: 'warning'
            })
            return
          }
          if (
            this.ruleForm.course_id.length < 1 ||
            !this.ruleForm.course_id[0]
          ) {
            return
          }
          if (this.$route.query.id) {
            let list = []
            for (let i = 0; i < this.ruleForm.course_id.length; i++) {
              let goodsCourseTime = []
              for (let j = 0; j < this.ruleForm.course_time_id[i].length; j++) {
                goodsCourseTime.push({
                  course_time_id: this.ruleForm.course_time_id[i][j]
                })
              }
              list.push({
                goods_id: this.$route.query.id,
                course_id: this.ruleForm.course_id[i],
                goods_course_time: goodsCourseTime
              })
            }
            let res = await goodsUpdate({
              'nice_goods_virtual.goods_name': this.ruleForm.goods_name,
              'nice_goods_virtual.main_pic': this.ruleForm.main_pic,
              'nice_goods_virtual.retail_price': this.ruleForm.retail_price,
              'nice_goods_virtual.original_price': this.originalPrice,
              'nice_goods_virtual.list_time': this.ruleForm.list_time,
              'nice_goods_virtual.delist_time': this.ruleForm.delist_time,
              'nice_goods_virtual.course_type': this.ruleForm.course_type,
              'nice_goods_virtual.is_recommend': this.ruleForm.is_recommend,
              'nice_goods_virtual.goods_type': this.ruleForm.goods_type,
              'nice_goods_virtual.id': this.$route.query.id,
              'nice_goods_virtual.course_count': list.length,
              'nice_goods_virtual.goods_tag':
                this.ruleForm.goods_tag && this.ruleForm.goods_tag.length
                  ? this.ruleForm.goods_tag.join(',')
                  : '',
              'nice_goods_virtual.activity_tag':
                this.ruleForm.activity_tag && this.ruleForm.activity_tag.length
                  ? this.ruleForm.activity_tag.join(',')
                  : '',
              'nice_goods_virtual.activity_tag_style': this.ruleForm
                .activity_tag_style,
              'nice_goods_virtual.apply_cardinal': this.ruleForm.apply_cardinal,
              'nice_goods_virtual.is_cardinal': this.ruleForm.is_cardinal,
              'nice_goods_virtual.cardinal_tag': this.ruleForm.cardinal_tag,
              'nice_goods_virtual.custom_date': this.ruleForm.custom_date,
              'nice_goods_virtual.priority': this.ruleForm.priority,
              'vo.list': list
            })
            // [{"goods_id":6,"course_id":"3","goods_course_time":[{"course_time_id":"4"},{"course_time_id":"5"}]},{"goods_id":6,"course_id":"8","goods_course_time":[{"course_time_id":"2"},{"course_time_id":"3"}]}]
            if (res[0]) {
              return
            }
          } else {
            let goodsCourse = []
            for (let i = 0; i < this.ruleForm.course_id.length; i++) {
              let goodsCourseTime = []
              for (let j = 0; j < this.ruleForm.course_time_id[i].length; j++) {
                goodsCourseTime.push({
                  course_time_id: this.ruleForm.course_time_id[i][j]
                })
              }
              goodsCourse.push({
                course_id: this.ruleForm.course_id[i],
                goods_course_time: goodsCourseTime
              })
            }
            let res = await tableInsert([
              {
                table_name: 'nice_goods_virtual',
                list: [
                  {
                    goods_name: this.ruleForm.goods_name,
                    main_pic: this.ruleForm.main_pic,
                    retail_price: this.ruleForm.retail_price,
                    original_price: this.originalPrice,
                    list_time: this.ruleForm.list_time,
                    delist_time: this.ruleForm.delist_time,
                    course_type: this.ruleForm.course_type,
                    is_recommend: this.ruleForm.is_recommend,
                    goods_course: goodsCourse,
                    course_count: goodsCourse.length,
                    goods_tag:
                      this.ruleForm.goods_tag && this.ruleForm.goods_tag.length
                        ? this.ruleForm.goods_tag.join(',')
                        : '',
                    activity_tag:
                      this.ruleForm.activity_tag &&
                      this.ruleForm.activity_tag.length
                        ? this.ruleForm.activity_tag.join(',')
                        : '',
                    activity_tag_style: this.ruleForm.activity_tag_style,
                    apply_cardinal: this.ruleForm.apply_cardinal,
                    cardinal_tag: this.ruleForm.cardinal_tag,
                    is_cardinal: this.ruleForm.is_cardinal,
                    custom_date: this.ruleForm.custom_date,
                    priority: this.ruleForm.priority,
                    goods_type: this.ruleForm.goods_type
                  }
                ]
              }
            ])
            if (res[0]) {
              return
            }
          }

          this.$message({
            message: '保存成功',
            type: 'success'
          })
          this.$router.push({ name: 'course-management' })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style scoped>
h2 {
  padding-left: 20px;
}
.u-form-box {
  width: 670px;
  padding-bottom: 50px;
}
.u-form-item-rate {
  padding-top: 9px;
}
.m-course-box {
  border-left: 3px solid #3e83f8;
}
.u-title-h2 {
  padding-left: 70px;
  margin-bottom: 40px;
}
.u-time-box {
  width: 100%;
}
.u-info-text {
  font-size: 12px;
}
</style>
